<?php
/*
Plugin Name: ShareOn
Plugin URI: http://www.williamyhuang.com
Description: Share posts to Scoop.It to create beautiful magazines and allow posts to be distributed through all the popular social media outlets. To get started <a href="options-general.php?page=share_on.php">click here</a>
Version: 0.2
Author: William Huang
Author URI: http://www.williamyhuang.com
License:
 ==============================================================================
 Copyright 2012 William Huang

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

if (!function_exists ('add_action')) {
		header('Status: 403 Forbidden');
		header('HTTP/1.1 403 Forbidden');
		exit();
}

if (!in_array('OAuth', get_loaded_extensions())) {
	wp_die(_e("Sorry, you don't have a required module loaded in PHP, specifically PECL OAuth.", 'TecBridge'));
}

require_once('ScoopitDatabase.php');
require_once('ScoopitSettings.php');
require_once('ScoopitMetabox.php');

$scoopitsettings = new ScoopitSettings();		
add_action('admin_init', 'shareOnInit');
add_filter('plugin_action_links', 'add_settings_link', 10, 2 );
register_activation_hook(__FILE__, 'share_on_install');
register_deactivation_hook(__FILE__, 'share_on_uninstall');
	
		
	
function shareOnInit() {
	global $current_user;
	get_currentuserinfo();
	
	$db = new ScoopitDatabase();
	$userID = $current_user->ID;
	$db->selectUserAndPlatform($userID, "Scoopit");
	$scoopitmetabox = new ScoopitMetabox($db);
}
	
function share_on_install () {
	add_option('share_on');
	
	ScoopitDatabase::createTable();
}

function share_on_uninstall() {
	delete_option('share_on');
	
	ScoopitDatabase::deleteTable();
}
	
function add_settings_link($links, $file) {
	if ($file == plugin_basename(__FILE__))
		$links[] = '<a href="options-general.php?page=share_on.php">'.__("Settings").'</a>';
		
	return $links;
}
?>